home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 1 / MacMania 1.toast / Educational / Education'More / A-C / CPUdemo2.0.cpt / lessons1.text < prev    next >
Text File  |  1990-07-30  |  13KB  |  219 lines

  1.  
  2. Lesson 1
  3. Introduction
  4.  
  5.      This program, CPUStructure, explains the inner workings of a hypothetical computer's Central Processing Unit (CPU). Though the CPU studied in this program is hypothetical, its basic principles of operation apply to most real-world CPUs.
  6.      The program is broken up into 20 lessons that progress from the very basic components of a computer (digital logic gates) up to an example of the operation of a complete CPU.
  7.      Because each lesson is dependent on material presented in previous lessons, it is highly recommended that the twenty lessons be studied in order.
  8.      
  9. Overview
  10.      
  11.      The CPU is the "brains" of the computer. Its function is to execute programs stored in main memory by fetching their instructions, examining them, and then executing them one after another. The CPU consists of three main parts:
  12.  
  13. Control Unit -
  14. responsible for fetching instructions from main memory and determining their type.
  15.  
  16. Arithmetic Logic Unit -
  17. performs mathematical and logical operations in order to carry out the instructions.
  18.  
  19. Scratchpad Registers -
  20. a small number of registers that make up a small, high-speed memory used to store results and control information. One of these registers is the Program Counter (PC), which keeps track of the next instruction that is to be executed in main memory. Another scratchpad register is the Instruction Register (IR), which holds the instruction that is currently being executed.
  21.  
  22.      The CPU is driven by a set of internal, inalterable instructions. These instructions, called microinstructions, are held in a section of Read Only Memory (ROM) within the CPU.
  23.      The microinstructions are in the form of a small computer program. They allow the CPU to carry out its functions, such as retrieving (fetching) code from main memory and performing mathematical and logical operations.
  24.      The microinstructions are carried out one after another, in sequential order, unless code in main memory directs the CPU to use a microinstruction that is out of sequence. 
  25.      The code in Main Memory is the code of the application (program) that is currently running. The CPU continually fetches pieces of this code. The code instructs the CPU as to which of its microinstructions it should use.
  26.      The execution of a program (such as MacPaint, MacWrite, etc) causes the CPU to continuously cycle through its internal set of microinstructions. The cycle can be outlined as:
  27.  
  28. 1. Fetch the next piece of code (instruction) from memory
  29. 2. Change the Program Counter so that it points to the following instruction
  30. 3. Determine the type of instruction just fetched
  31. 4. If the instruction uses data in memory, determine where the data is
  32. 5. Fetch the data, if any, into internal CPU scratchpad registers
  33. 6. Execute the instruction
  34. 7. Store the results in the proper place.
  35. 8. Go to step 1 (repeat the cycle)
  36.  
  37.  
  38.      As you study the Lessons, keep in mind the difference between instructions and microinstructions:
  39.  
  40. INSTRUCTIONS -
  41. are contained in the code of the program that the computer is currently executing (running). They are fetched from main memory by the CPU. They tell the CPU which of its microinstructions it should use.
  42.  
  43. MICROINSTRUCTIONS -
  44. are permanently contained within the Control Unit of the CPU. They contain information that other parts of the CPU use in order to carry out the action specified by the INSTRUCTION from memory. 
  45.  
  46.          The differences between instructions and microinstructions will become more apparent as you reach the final Lessons.
  47.  
  48.  
  49. THE GRAPHIC WINDOW
  50.  
  51.          The simulation in the Graphic Window demonstrates the above eight steps that the CPU continuously cycles through.
  52.  
  53.  
  54. Lesson 2 
  55. Digital Logic
  56.  
  57.      At the lowest level, computer hardware is made up of digital logic gates. They are the basic elements from which all digital computers are constructed.
  58.      A digital logic gate uses only two logical values: "0" and "1". The gate interprets a voltage signal that is between 0 and 1 volt as a binary 0. It interprets a voltage signal that is between 2 and 5 volts as a binary 1. Voltages that do not fall within this range are not permitted.
  59.      Voltages that are interpreted as binary 1 are referred to as HIGH or Vcc. Voltages that are interpreted as binary 0 are referred to as LOW or ground.
  60.      Digital gates are small electronic devices that take in these voltage signals, interpret them as "1's" or "0's", and then output a voltage signal, which is also either a "1" or a "0".
  61.      The six principle digital logic gates are pictured in the Graphics Window. The name and function of each is listed below:
  62.  
  63. OR gate - 
  64. if any one or more of the gate's inputs has a value of "1", the output of the gate is a "1". If none of the inputs is a "1", the output is a "0". 
  65.  
  66. AND gate -
  67. if and only if all of the inputs are "1's", the output of the gate is a "1". If any of the inputs is a "0", the output is a "0".
  68.  
  69. NOT gate (inverter) -
  70. the output of the gate has a value opposite of the gate's one input value: if the input is a "0", the output is a "1". If the input is a "1", the output is a "0".
  71.  
  72. NOR gate -
  73. is the opposite of an OR gate. If any one or more of the gates inputs has a value of "1", the output of the gate is a "0". If none of the inputs is a "1", the output is a "1".
  74.  
  75. XOR gate -
  76. exclusive OR gate. If none or both of the gate's inputs has a value of "1", the output of the gate is a "0". If one of the inputs is a "1", the output is a "1".
  77.  
  78. NAND gate -
  79. is the opposite of an AND gate. If and only if all of the inputs are "1's", the output of the gate is a "0". If any of the inputs is a "0", the output is a "1".
  80.  
  81.      By combining these six types of logic gates into electrical circuits, digital circuits are constructed.
  82.  
  83.      All logic gates have just one output. A NOT gate, also called an inverter, may have only one input. The other five gate types, pictured in the Graphics Window with two inputs, may have two or more inputs. The same principles apply to a logic gate regardless of the number of inputs it has.
  84.  
  85.  
  86. THE GRAPHIC WINDOW
  87.  
  88.          The Graphic Window shows each of the five basic gates mentioned above. The Edit Boxes serve as the inputs to each gate. Enter a "1" or a "0" in each of the Edit Boxes, then run the simulation to see the gate outputs.
  89.  
  90.  
  91. Lesson 3 
  92. Multiplexer
  93.  
  94.          A multiplexer (also called a MUX) is a circuit with two or more data inputs, one data output, and control (select) lines. The number of data inputs that the circuit may have is dependent on the number of control lines. If a multiplexer has n control lines, it can then handle 2^n data inputs. All multiplexers have just one output.
  95.          The number of data inputs gives the multiplexer its specific name: a four input, one output multiplexer is called a 4-to-1 MUX, an eight input multiplexer is called an 8-to-1 MUX, etc. 
  96.          The values on the control lines tell the multiplexer which one of the data inputs should be passed through the circuit to the output. The purpose of the MUX is to select information from one of several input terminals and route that input to a single output lead. 
  97.          An application of a multiplexer is a parallel-to-serial converter. By putting 4 bits of data on the input lines of a 4-to-1 MUX, and then stepping the control lines sequentially from 00 to 11 (binary: 00 01 10 11), the 4 bits are put onto the output line in series. 
  98.  
  99.  
  100. THE GRAPHIC WINDOW
  101.  
  102.          The Graphic Window shows a four-input multiplexer circuit (4-to-1 MUX). As defined above, a multiplexer has 2^n data inputs, one output, and n control lines. In this example, n = 2 (two control lines: S1, S0).  Then:
  103.  
  104.      # of control lines = n = 2
  105.      # of data inputs  = 2^n = 2^2 = 4
  106.      # of outputs = 1 
  107.  
  108.          The data on the four data input lines, D0-D3, are arbitrary values. Assume these "1's" and "0's" are data coming from some other part of a larger circuit.
  109.          The Edit Boxes allow you to alter the values of the control lines. Enter a "1" or a "0" in each of the Edit Boxes, then run the simulation to see the MUX output.
  110.  
  111. control lines    output
  112.   S1   S0          F
  113.  
  114.    0    0         DO
  115.    0    1         D1
  116.    1    0         D2
  117.    1    1         D3
  118.  
  119.  
  120. Lesson 8 
  121. 8-Bit Arithmetic Logic Unit
  122.  
  123.          The 1-bit ALU of Lesson 7 is available as a chip known as a "bit slice". Bit slices allow an ALU to be built to any desired "width" (word size, number of bits). By joining eight 1-bit slices together, an 8-bit ALU is formed. To join two 1-bit ALUs, the Carry Out (CO) of one is used as the Carry In (CI) of the next. An 8-bit ALU is more practical than the 1-bit ALU because it can perform logic and addition operations on two 8-bit words (on two bytes). 
  124.          The 8-bit ALU has two features not found on the 1-bit ALU: a zero flag (Z flag) and a negative flag (N flag). Flags are control outputs. They indicate whether or not a particular condition has been met. This information may be passed along the output to control some other component in a larger circuit.
  125.          If the result of the ALU operation is zero, the Z flag is "set" (given a value of "1", "on"). If the result of the ALU operation is a negative value, the N flag is "set" (set to "1", "on"). Two other control outputs that an ALU may have are flags to indicate that an overflow or a carry out of the highest bit has occurred. 
  126.  
  127.  
  128. { *************************** }
  129. The following section describes the ALU's representation of negative numbers. If you set S1=1,S0=1 for addition, and you do not understand how the sum of the A and B words was determined, read this section.  
  130. { *************************** }
  131.  
  132. • THE ALUs EXPRESSION OF NUMBERS IN 2's COMPLEMENT FORM 
  133.  
  134.          The 8-bit ALU of this example uses "2's complement form" to express negative numbers. To express a binary negative number in 2's complement, follow these steps:
  135.  
  136.     1)  start with the binary value of the absolute value of the base10 number
  137.     2)  reverse each digit of the positive number 
  138.             (all "1's" become "0's", all "0's" become "1's")
  139.     3)  add "1" to the result
  140.  
  141.  
  142. EXAMPLE 1, 2's complement:
  143.          Express decimal "-5" in 2's complement form using the above steps.
  144.  
  145.     1)   absolute value of -5  =  5
  146.     
  147.            5 base10  =  00000101 base2
  148.  
  149.     2)   reverse digits:   00000101  -->>  11111010
  150.  
  151.     3)   add "1"    11111010
  152.                 +       1
  153.                 __________
  154.                  11111011
  155.  
  156.      result:   -5 base10  =  11111011 base2, 2's complement
  157.  
  158.  
  159.          Note that the High Order bit (HO,leftmost bit) of the result (11111011) is a "1". This will ALWAYS be the case. This fact is made use of by the ALU's N flag. The ALU simply "taps" the High Order bit of the result (F7) and sends it out as the N flag. An N flag value of "1" means the ALU result is negative.
  160.  
  161.  
  162. EXAMPLE 2, addition involving a negative number:
  163.          Express the sum of decimal "-5" added to decimal "+3" as a binary number.
  164.  
  165.   •   from Example 1, -5 base10  =  11111011 base2, 2's complement
  166.  
  167.   •   +3 base10  =  00000011 base2
  168.  
  169.   •   -5 + (+3):      11111011    (-5)
  170.                     + 00000011    (+3)
  171.                     __________
  172.                       11111110    (-2)
  173.  
  174.   result:   -5 + (+3) =  11111110  , 2's complement
  175.  
  176. Note that the High Order bit is a "1", signifying a negative number.
  177.  
  178. To find the absolute value of a 2's complement number in decimal form, follow these steps:
  179.  
  180.     1)  reverse each digit of the 2's complement number 
  181.     2)  add "1" to the result
  182.  
  183. To verify the result of Example 2, use the above steps:
  184.  
  185.   from result of Example 2: -2 base10   =  11111110   , 2's complement
  186.  
  187.   1)   reverse digits:   11111110  -->>  00000001
  188.  
  189.   2)   add "1"    00000001
  190.                 +        1
  191.                 __________
  192.                   00000010
  193.  
  194.  
  195.      result:   absolute value of -5 + (+3) = 2
  196.  
  197.  
  198. THE GRAPHIC WINDOW
  199.  
  200.          The Graphic Window shows an 8-bit arithmetic logic unit (8-bit ALU). The Edit Boxes allow you to enter two 8-bit words (A and B) that will have some logic operation or addition performed on them. You may also enter the control (select) line values (S1,S0) that determine which operation will be performed. The ALU is capable of performing one of four operations (the same four operations as the 1-bit ALU, Lesson 7): 
  201.  
  202.    • logic AND on A,B
  203.    • logic OR on A,B
  204.    • invert B
  205.    • add A to B
  206.  
  207. Enter a "1" or a "0" in each of the Edit Boxes, then run the simulation. The result of the logic operation appears at output F.
  208.  
  209.   control lines    output result
  210.      S2   S1        (operation)
  211.  
  212.      0    0          A AND B
  213.      0    1          A OR B
  214.      1    0          B NOT (invert B)
  215.      1    1          A + B (A added to B)
  216.  
  217.  
  218.  
  219.